const express = require('express')
const app = express()
const mysql = require('mysql')
const db = mysql.createPool({
  host: 'localhost',
  port: 3306,
  user: 'root',
  password: '123456',
  database: "shopdb"
})
//1.增
app.get('/one', (req, res) => {
  let sql = "insert into t_goods(title,imagePath,price) values('OPPO reno clow','./images/05.png',3500)"
  db.query(sql, [], (err, result) => {
    res.send(result)
  })
})
//2.删
app.get('/two', (req, res) => {
  let sql = "delete from t_goods where id=?"
  db.query(sql, [1], (err, result) => {
    res.send(result)
  })
})
//改
app.get('/three', (req, res) => {
  let sql = "update t_goods set price=3000 where id=?"
  db.query(sql, [2], (err, result) => {
    res.send(err)
  })
})
//查
app.get('/four', (req, res) => {
  let sql = "select title,price from t_goods"
  db.query(sql, [], (err, result) => {
    res.send(result)
  })
})
app.listen(3001, () => {
  console.log('欢迎光临!');
})